﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Slwy.Data.Entity.Helper;
using SqlSugar;

namespace Slwy.Data.Entity.SqlSugarExtensions
{
    public static class UpdateableProviderExtensions
    {
        public static IUpdateable<T> Table<T>(this IUpdateable<T> superset, string tableName) where T : class, new()
        {
            return superset.AS(tableName);
        }

        /// <summary>
        /// 获取月表名
        /// </summary>
        /// <typeparam name="T">Entity实体</typeparam>
        /// <param name="superset">更新器</param>
        /// <param name="keyId">keyId</param>
        /// <exception cref="System.ArgumentException">>如果从keyId获取表名失败引发异常</exception>
        /// <returns></returns>
        public static IUpdateable<T> TableYYYY<T>(this IUpdateable<T> superset, string keyId) where T : class, new()
        {
            var tableName = TableHelper.GetTableName<T>(keyId);
            superset.UpdateBuilder.TableName = tableName;
            return superset;
        }

        /// <summary>
        /// 获取月表名
        /// </summary>
        /// <typeparam name="T">Entity实体</typeparam>
        /// <param name="superset">更新器</param>
        /// <param name="keyId">keyId</param>
        /// <exception cref="System.ArgumentException">>如果从keyId获取表名失败引发异常</exception>
        /// <returns></returns>
        public static IUpdateable<T> TableYYYYMM<T>(this IUpdateable<T> superset, string keyId) where T : class, new()
        {
            var tableName = TableHelper.GetTableName<T>(keyId, "YYMM");
            superset.UpdateBuilder.TableName = tableName;
            return superset;
        }
    }
}
